package hongcaosp.app.android.user.member;

import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import hongcaosp.app.android.R;
import hongcaosp.app.android.common.BaseHolder;

public class MemberItemHolder extends BaseHolder<IMemberDate> {
    private TextView desTV,lastPriceTV,currentPriceTV;
    private MemberItemSelectListener itemSelectListener;
    private boolean isSelect;
    private IMemberDate date;

    public void setItemSelectListener(MemberItemSelectListener itemSelectListener) {
        this.itemSelectListener = itemSelectListener;
    }

    public MemberItemHolder(View itemView) {
        super(itemView);
        desTV = itemView.findViewById(R.id.des_tv);
        lastPriceTV = itemView.findViewById(R.id.last_price);
        lastPriceTV.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG| Paint.ANTI_ALIAS_FLAG);
        currentPriceTV = itemView.findViewById(R.id.current_price);
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isSelect = !isSelect;
                setSelected(isSelect);
                if (isSelect && itemSelectListener != null) {
                    itemSelectListener.onItemSelected(MemberItemHolder.this);
                }
            }
        });
    }

    @Override
    public void setData(IMemberDate iMemberDate) {
        this.date = iMemberDate;
        desTV.setText(iMemberDate.getMemberStr());
        if (iMemberDate.getLastPrice() > 0) {
            lastPriceTV.setText("¥" + iMemberDate.getLastPrice());
        } else {
            lastPriceTV.setText("");
        }
        currentPriceTV.setText("¥" + iMemberDate.getCurrentPrice());
    }

    public void setSelected(boolean isSelect) {
        this.isSelect = isSelect;
        this.itemView.setSelected(isSelect);
    }

    public IMemberDate getDate() {
        return date;
    }

    public interface MemberItemSelectListener {
        void onItemSelected(MemberItemHolder memberItemHolder);
    }
}
